package com.ljsw.adapter;

import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
import com.ljsw.activity.R;
import com.ljsw.entity.RenWuClass;
import com.ljsw.view.DeleteListView;
/**
 * 我的任务适配器    任务完成适配器(这2个显示内容风格一样 公用)
 * 作者: 石锚
 * 版本: 1.0
 * 日期: 2015-10-10
 */
public class RenWuAdapter extends BaseAdapter{
	
	public RenWuAdapter(Context context, ArrayList<RenWuClass> list) {
		super();
		this.context = context;
		this.list = list;
		
	}
	
	public RenWuAdapter(Context context, ArrayList<RenWuClass> list,DeleteListView mListView) {
		super();
		this.context = context;
		this.list = list;
		this.listView = mListView;
	}
	
	private Context context;
	private ArrayList<RenWuClass> list = new ArrayList<RenWuClass>();
	private DeleteListView listView;
	
	
	public void updateList(ArrayList<RenWuClass> aa){
		this.list = aa;
		this.notifyDataSetChanged();
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	public View getView(final int arg0, View view, ViewGroup arg2) {
		ViewHodler hodler;
		if(view==null){
			hodler = new ViewHodler();
			view = LayoutInflater.from(context).inflate(R.layout.renwu_list_item, null);
			hodler.service = (TextView) view.findViewById(R.id.service1);
			hodler.date = (TextView) view.findViewById(R.id.date1);
			hodler.line = (TextView) view.findViewById(R.id.line1);
			hodler.time = (TextView) view.findViewById(R.id.time1);
			hodler.company = (TextView) view.findViewById(R.id.area1);
			hodler.address = (TextView) view.findViewById(R.id.stree1);
			hodler.type = (TextView) view.findViewById(R.id.type1);
			hodler.state = (TextView) view.findViewById(R.id.state1);
			hodler.delbtn = (Button) view.findViewById(R.id.id_item_btn);
			view.setTag(hodler);
		}else{
			hodler = (ViewHodler) view.getTag();
		}
		if("0".equals(list.get(arg0).getService())){
			hodler.service.setText("上门收款");
		}else if("1".equals(list.get(arg0).getService())){
			hodler.service.setText("上门收单");
		}else if("2".equals(list.get(arg0).getService())){
			hodler.service.setText("上门送款");
		}else if("3".equals(list.get(arg0).getService())){
			hodler.service.setText("上门送单");
		}
		if("0".equals(list.get(arg0).getType())){
			hodler.type.setText("半封包");
		}else if("1".equals(list.get(arg0).getType())){
			hodler.type.setText("全封包");
		}
		if("0".equals(list.get(arg0).getState())){
			hodler.state.setText("未领取");
		}else if("1".equals(list.get(arg0).getState())){
			hodler.state.setText("已领取");
		}else if("2".equals(list.get(arg0).getState())){
			hodler.state.setText("已装箱");
		}else{
			hodler.state.setText("已完成");
		}
		hodler.date.setText(list.get(arg0).getDate());
		hodler.line.setText(list.get(arg0).getLine());
		hodler.time.setText(list.get(arg0).getStartTime()+"--"+list.get(arg0).getEndTime());
		hodler.company.setText(list.get(arg0).getCompany());
		hodler.address.setText(list.get(arg0).getAddress());
		
		hodler.delbtn.setOnClickListener(new OnClickListener() {  
           
            public void onClick(View v) {  
            	list.remove(arg0);  
            //    notifyDataSetChanged(); 
                updateList(list);
                listView.turnToNormal();  
            }  
        });
		return view;
	}
	/**
	 * XML文件对应的实体控件
	 * 作者: 石锚
	 * 版本: 1.0
	 * 日期: 2015-10-10
	 */
	static class ViewHodler{
		TextView service,date,line,time,company,address,type,state;
		Button delbtn;
	}

}
